﻿$.MGJ.AreaManage = [];
(function () {
    var _this = $.MGJ.AreaManage;
    $.extend($.MGJ.AreaManage, {


    });
})(jQuery);

(function () {
    var _this = $.MGJ.AreaManage;
    $.extend($.MGJ.AreaManage, {


    });
})(jQuery);

(function () {
    var _this = $.MGJ.AreaManage;
    $.extend($.MGJ.AreaManage, {
        AreaManagerList: null,
        ConditionModel: {
            pageIndex: 1,
            pageSize: 10,
            searchKey: null
        },
        //获取
        GetAreaManageList: function (pageindex) {
            _this.ConditionModel.pageIndex = pageindex || 1;
            _this.ConditionModel.searchKey = removeSpace($("#SearchKey").val());
            $.L.ajaxHandle({
                url: ACTION_URL("GetAreaManagerList", "Manager"),
                data: _this.ConditionModel,
                success: function (response) {
                    _this.AreaManagerList = response;
                    $("#SaleAreaData").L_bindingDataList(response);
                }
            });
        },
        ExprotArea: function (ele) {
            $("input.AllClickChild:checked").each(function () {
                info.push($(this).attr('ID'));
            });
            if (info.length == 0) {
                $.L.msgError("请选择要导出的数据信息！");
                return
            }
            
            if (!$(ele).find('.no-result').hasClass('no-result')) {
                window.open(ACTION_URL("AreaExcelExport", "Manager") + "?Key=" + info);
            }
            else {
                $.L.msgWarning('导出数据不能为空！')
            }


        },
        DelteAreaManager: function (item) {
            var _id = $(item).attr("Id");
            $.L.msgConfirm("确认删除该记录?", function () {
                $.L.ajaxHandle({
                    url: ACTION_URL("DeleteAreaManager", "Manager"),
                    data: { id: _id },
                    success: function (response) {
                        if (response === "0000") {
                            _this.GetAreaManageList(_this.ConditionModel.pageIndex);
                        } else if (response === "4445") {
                            $.L.msgWarning("已被使用资源不可删除");
                        } else if (response === "4444") {
                            $.L.msgError("删除失败");
                        }
                    }
                })
            })
        },
        EditAreaManager: function (item) {
            var _id = Number($(item).attr("Id"));
            _this.Dialog_AEditAreaObj = $.L.dialog({
                url: ACTION_URL("AEditArea", "Manager") + "?id=" + _id,
                title: "新增或编辑片区管理",
                width: 800,
                height: 'auto',
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            var bootstrapValidator = $("#AreaManagerModel").data('bootstrapValidator').validate();
                            if (bootstrapValidator.isValid()) {
                                $(".btn-primary").attr("disabled", true);
                                $.L.ajaxHandle({
                                    url: ACTION_URL("EditAreaSave", "Manager"),
                                    type: "POST",
                                    data: $("#AreaManagerModel").serialize(),
                                    success: function (response) {
                                        _this.Dialog_AEditAreaObj.close();
                                        _this.GetAreaManageList(_this.ConditionModel.pageIndex);
                                        if (response === "0000") {
                                            $.L.msgSuccess("修改成功");
                                        } else if (response === "1111") {
                                            $.L.msgWarning("存在相同名称片区");
                                        } else if (response === "4444") {
                                            $.L.msgError("修改失败");
                                        }
                                    }
                                })
                            }
                            else {
                                $.L.msgError("请检查数据格式！");
                            };

                            
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });
        },
        AddAreaManager: function () {
            _this.Dialog_AEditAreaObj = $.L.dialog({
                url: ACTION_URL("AEditArea", "Manager"),
                title: "新增或编辑片区管理",
                width: 800,
                height: 'auto',
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            var bootstrapValidator = $("#AreaManagerModel").data('bootstrapValidator').validate();//触发全部验证
                            if (bootstrapValidator.isValid()) {
                                $(".btn-primary").attr("disabled", true);
                                $.L.ajaxHandle({
                                    url: ACTION_URL("AddAreaSave", "Manager"),
                                    type: "POST",
                                    data: $("#AreaManagerModel").serialize(),
                                    success: function (response) {
                                        _this.GetAreaManageList();
                                        if (response === "0000") {
                                            $.L.msgSuccess("添加成功");
                                        } else if (response === "1111") {
                                            $.L.msgWarning("存在相同名称片区");
                                        } else if (response === "4444") {
                                            $.L.msgError("添加失败");
                                        }
                                        _this.Dialog_AEditAreaObj.close();
                                    }
                                })
                            }
                            else {
                                $.L.msgError("请检查数据格式！");
                            };
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });
        }

    });
})(jQuery);
